package com.example.foodisimportant.StudentViewActivity.Fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.example.foodisimportant.LoginActivity.LoginTest;
import com.example.foodisimportant.PersonalInformationActivity.PersonalInformationActivity;
import com.example.foodisimportant.R;
import com.example.foodisimportant.StudentViewActivity.StudentViewActivity;

import java.security.PublicKey;

public class SettingsFragment extends Fragment {

    private ImageButton mBtnInformationSettings,mBtnSettings;
    private ImageView mIvheadicon;
    private TextView mTvname;
    String haoma,mima;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View SettingsLayout=inflater.inflate(R.layout.fragment_settings,container,false);
        mBtnInformationSettings=SettingsLayout.findViewById(R.id.edit_user);
        mBtnSettings=SettingsLayout.findViewById(R.id.setting);
        mIvheadicon=SettingsLayout.findViewById(R.id.wode_touxiang);
        mTvname=SettingsLayout.findViewById(R.id.wode_nicheng);
        mBtnInformationSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), PersonalInformationActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("number", haoma);
                bundle.putString("password", mima);
                intent.putExtra("bun",bundle);
                startActivity(intent);
            }
        });
        return SettingsLayout;
    }

    //传输数据
    public static SettingsFragment newInstance(int a) {
        Bundle args = new Bundle();
        SettingsFragment fragment = new SettingsFragment();
        args.putInt("a",a);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Bundle arguments=getArguments();
        if (arguments!=null){
            mTvname.setText(arguments.getString("a",null));
            mIvheadicon.setImageResource(R.mipmap.fastfood);
        }
    }

    //更新数据
    public void updateArgument(String pageType){
        this.mTvname.setText(pageType);
        Bundle args=getArguments();
        if (args!=null){
            args.putString("a",pageType);
        }
    }
}
